/*********************************** (C) COPYRIGHT ******************************
 * address: https://gitee.com/liuniansihuo/multitasks-os
 *
 * Change Logs:
 * Date			Author      	Notes
 * 2019-06-16	LiuHuo			first version
 *
 * Modify Note:  for support typeof() arm gcc must set zhe  "--gnu"
*******************************************************************************/

#ifndef list_H_
#define list_H_


struct list_head
{
	struct list_head *next; // point zhe next node
	struct list_head *prev;// point zhe prev node
};

#define LIST_HEAD_INTT(name) {&(name), &(name)}
#define LIST_HEAD(name) 	struct list_head name = LIST_HEAD_INIT(name)


#define offset_of(type, memb)  ((unsigned long)(&((type *)0)->memb))
#define  container_of(ptr, type, member) ( (type*)( (char*)(ptr) - offset_of(type, member) ) )


/*****************note:in circle ,it must be not delet zhe  element****************/
#define list_entry(ptr, type, member)  container_of(ptr, type, member)

#define list_for_each(pos,head) for(pos=(head)->next; pos != (head); pos=pos->next)

#define list_for_each_prev(pos,head) for(pos=(head)->prev; pos != (head);pos=pos->prev)
//note : if use zhe typeof, it is must be done:options for target ->C/C++->Misc controls :--gnu -O0 -g -W
#define list_for_each_entry(pos,head,member) for(pos=list_entry((head)->next, typeof(*pos), member);&pos->member!=(head);pos=list_entry(pos->member.next, typeof(*pos), member))

#define list_for_each_entry_reverse(pos,head,member) for(pos=list_entry((head)->prev, typeof(*pos), member);&pos->member!=(head);pos=list_entry(pos->member.prev, typeof(*pos), member))

/*****************note:in circle ,it can be  delet zhe  element****************/
#define list_for_each_safe(pos,n,head) for(pos=(head)->next,n=pos->next; pos != (head); pos=n,n=pos->next)

#define list_for_each_prev_safe(pos,n,head) for(pos=(head)->prev, n=pos->prev; pos != (head);pos=n, n=pos->prev)

#define list_for_each_entry_safe(pos,n,head,member) for(pos=list_entry((head)->next, typeof(*n), member),n=list_entry((pos)->member.next, typeof(*n), member);\
														&pos->member!=(head);\
														pos=n,n=list_entry((pos)->member.next, typeof(*n), member))

#define list_for_each_entry_safe_reverse(pos,n,head,member) for(pos=list_entry((head)->prev, typeof(*n), member),n=list_entry((pos)->member.prev, typeof(*n), member);\
														&pos->member!=(head);\
														pos=n, member),n=list_entry((pos)->member.prev, typeof(*n), member))






void list_init(struct list_head *head);
void list_add(struct list_head *new, struct list_head *head);
void list_add_tail(struct list_head *new, struct list_head *head);
void list_del(struct list_head *entry);
void list_del_init(struct list_head *entry);
void list_replace(struct list_head *old, struct list_head *new);
void list_replace_init(struct list_head *old, struct list_head *new);
void list_move(struct list_head *list, struct list_head *head);
void list_move_tail(struct list_head *list, struct list_head *head);
void list_splice(struct list_head *list, struct list_head *head);
void list_splice_tail(struct list_head *list, struct list_head *head);
void list_splice_init(struct list_head *list, struct list_head *head);
void list_splice_tail_init(struct list_head *list, struct list_head *head);
//void list_cut_position(struct list_head *list, struct list_head *head,struct list_head *entry);
int list_is_last(const struct list_head *list,const struct list_head *head);
int list_empty(const struct list_head *head);
int list_is_singular(const struct list_head *head);
int list_is_exit(const struct list_head *list,const struct list_head *head);


#endif
